
/**
 * Created by user on 2018/5/4.
 */
import React from 'react'
import { Link } from 'dva/router'
import NProgress from 'nprogress'
import PropTypes from 'prop-types'
import { connect } from 'dva'
import { Layout } from 'antd'
import { withRouter } from 'dva/router'
import { openPage } from '@/config'
import styles from './app.less'

import SHeader from '@/components/custom/Header'
import SBread from '@/components/custom/Bread'
import MSider from '@/components/custom/MSider'

const { Content, Footer } = Layout
// const { Header, Bread } = MyLayout

let lastHref

const App = ({ children, dispatch, app, location, loading }) => {
  let { pathname } = location
  pathname = pathname.startsWith('/') ? pathname : `/${pathname}`
  const { href } = window.location
  NProgress.start()
  if (lastHref !== href) {
    NProgress.start()
    if (!loading.global) {
      NProgress.done()
      lastHref = href
    }
  }

  if (openPage && openPage.includes(pathname)) {
    return (
      <div>
        {children}
      </div>
    )
  }
  return (
    <Layout className={styles.app_container}>
      <MSider location={location}/>
      <Layout className={styles.screen}>
        <SHeader></SHeader>
        <Content className={styles.app_content}>
          <SBread location={location}/>
          {children}
        </Content>
        <Footer >
          222
        </Footer>
      </Layout>
    </Layout>
  )
}

export default withRouter(connect(({ app, loading }) => ({ app, loading }))(App))
